import  AutoUploadOnline from '@/library/autoUploadOnline/autoUploadOnline.js';


function checkNetworkState(){
	uni.getNetworkType({
		complete: e => {
				let networkType = e.networkType || 'none';
			    if('none'==networkType){
					let pages  = getCurrentPages();
					let page = pages[pages.length - 1] 
					console.log(page)
					if(page&&page.route&&'pagesNotLogin/netstate/netstate'!=page.route){
						uni.navigateTo({
							url:'/pagesNotLogin/netstate/netstate'
						})
					}
					uni.showToast({
						icon:'none',
						title:'当前无网络，请检查您的网络链接'
					})
				}
		}
	});
}


//监听网络变化回调函数
let OnNetworkStatusChangeCallback = function (res){
	console.log("网络连接状态：",res.isConnected);
	console.log("网络类型：",res.networkType);
	if(res.isConnected){
		console.log("网络已连接");
		// #ifdef APP-PLUS
		  AutoUploadOnline("test");//自动上传未上传的数据
		// #endif
	  
	}else{
		console.log("网络已断开");
		let pages  = getCurrentPages();
		let page = pages[pages.length - 1] 
		console.log(page)
		if(page&&page.route&&'pagesNotLogin/netstate/netstate'!=page.route){
			uni.navigateTo({
				url:'/pagesNotLogin/netstate/netstate'
			})
		}
		
		uni.showToast({
			icon:'none',
			title:'当前无网络，请检查您的网络链接'
		})
	}
}

function StartOnNetWorkListen(){
	uni.offNetworkStatusChange(OnNetworkStatusChangeCallback);
	uni.onNetworkStatusChange(OnNetworkStatusChangeCallback);
	console.log("StartOnNetWorkListen")
}
checkNetworkState();
StartOnNetWorkListen();